package com.food.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.food.dao.service.MemberService;
import com.food.dao.service.RecipeService;
import com.food.model.Member;
import com.food.model.Recipe;


@WebServlet("/member/HisRecipe")
public class HisRecipe extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RecipeService service = new RecipeService();
//		HttpSession session = request.getSession();
//		Member member = (Member)session.getAttribute("user");
		
		int hismbid = Integer.parseInt(request.getParameter("hismbid"));
		System.out.println(hismbid);
		Recipe recipe = new Recipe();
		recipe.setMbid(hismbid);
		List<Recipe> coll = service.findRecipeByMb(recipe);
		
		Member member = new Member();
		MemberService memberService = new MemberService();
		member.setMbid(hismbid);
		member = memberService.findMember(member);
		
		
		request.setAttribute("mbRecipe", coll);
		request.setAttribute("his", member);
		
		
//		if(request.getAttribute("fail")!=null)
//			request.removeAttribute("fail");
//		
//		if(request.getAttribute("success")!=null)
//			request.removeAttribute("success");
		
		RequestDispatcher rd = request
				.getRequestDispatcher("/member/hisindex.jsp");
		rd.forward(request, response);
		return;
	}

}
